home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Dev / SpeakFreely_Src / gsm / tls / sweet.c < prev    next >
C/C++ Source or Header  |  2000-05-27  |  1KB  |  67 lines

  1.  /*
  2.   * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3.   * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
  4.   * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5.   */
  6.  
  7. /*$Header: /home/kbs/jutta/src/gsm/gsm-1.0/tls/RCS/sweet.c,v 1.1 1992/10/28 00:28:39 jutta Exp $*/
  8.  
  9. /* Generate code to unpack a bit array from name:#bits description */
  10.  
  11. #include    <stdio.h>
  12. #include    "taste.h"
  13. #include    "proto.h"
  14.  
  15. void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
  16. {
  17.     struct spex    * sp = s_spex;
  18.     int        bits = 8;
  19.     int        vars;
  20.  
  21.     if (!n_spex) return;
  22.  
  23.     vars = sp->varsize;
  24.  
  25.     while (n_spex) {
  26.  
  27.         if (vars == sp->varsize) {
  28.             printf("\t%s  = ", sp->var);
  29.         } else printf("\t%s |= ", sp->var);
  30.  
  31.         if (vars == bits) {
  32.     
  33.             if (bits == 8) printf( "*c++;\n" );
  34.             else printf( "*c++ & 0x%lX;\n",
  35.                 ~(0xfffffffe << (bits - 1)) );
  36.             
  37.             if (!-- n_spex) break;
  38.             sp++;
  39.             vars = sp->varsize;
  40.             bits = 8;
  41.  
  42.         } else if (vars < bits) {
  43.  
  44.             printf( "(*c >> %d) & 0x%lX;\n", 
  45.                 bits - vars,
  46.                 ~(0xfffffffe << (vars - 1)));
  47.  
  48.             bits -= vars;
  49.             if (!--n_spex) break;
  50.             sp++;
  51.             vars = sp->varsize;
  52.  
  53.         } else {
  54.             /*   vars > bits.  We're eating lower-all of c,
  55.              *   but we must shift it.
  56.              */
  57.             printf(    "(*c++ & 0x%X) << %d;\n",
  58.                 ~(0xfffffffe << (bits - 1)),
  59.                 vars - bits );
  60.  
  61.             vars -= bits;
  62.             bits = 8;
  63.         }
  64.     }
  65. }
  66.  
  67.